home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 7661 / 7661.xpi / chrome / isreaditlater.jar / content / RILlogin.js < prev    next >
Text File  |  2009-12-10  |  6KB  |  159 lines

  1. function RILlogin() {
  2.         this.showPanel('choice');
  3. }
  4. RILlogin.prototype = {
  5.         
  6.         showPanel : function(panel)
  7.         {
  8.                 if (this.currentPanel)
  9.                         RIL.xul('login_panel_'+this.currentPanel).hidden = true;
  10.                 
  11.                 this.currentPanel = panel;
  12.                 RIL.xul('login_panel_'+this.currentPanel).hidden = false;
  13.         },
  14.         
  15.         checkEnterKey : function()
  16.         {
  17.                 if (this.currentPanel == 'login')
  18.                         this.login();
  19.                 else if (this.currentPanel == 'signup')
  20.                         this.signup();
  21.         },
  22.         
  23.         login : function()
  24.         {
  25.                 let username = RIL.xul('login_username').value;
  26.                 let password = RIL.xul('login_password').value;                    
  27.                 
  28.                 if (username.length == 0 || password.length == 0)
  29.                 {
  30.                         RIL.APP.PROMPT.alert(window, 'Read It Later', RIL.l('mustEnterUserAndPass') );
  31.                         return false;
  32.                 }
  33.                 
  34.                 RIL.addClass( RIL.xul('login') , RIL.XULnamespace + 'loading' );
  35.                 RIL.APP.SYNC.login(username, password, this, 'loginCallback');            
  36.         },
  37.  
  38.         loginCallback : function(request) {
  39.                         
  40.                 RIL.removeClass( RIL.xul('login') , RIL.XULnamespace + 'loading' );
  41.                 
  42.                 try {
  43.                         
  44.                 if (request.success)
  45.                 {
  46.                         this.saveLogin('login');
  47.                         
  48.                         // Sync and show list
  49.                         try {
  50.                                 
  51.                                 let w = this.getTopWindow();    
  52.                                 
  53.                                 w.RIL.openListAfterLogin();
  54.                                 
  55.                                 window.close();
  56.                                 
  57.                         } catch(e) {
  58.                                 // if we can't connect to the current window, just give up and close the login dialog
  59.                                 window.close();
  60.                         }
  61.  
  62.                 }
  63.                 else
  64.                 {
  65.                         this.handleError(request, 'logging in');
  66.                 }
  67.                 
  68.                 } catch(e) { Components.utils.reportError(e); }
  69.         },
  70.         
  71.         signup : function()
  72.         {
  73.                 let username             = RIL.xul('signup_username').value;
  74.                 let password             = RIL.xul('signup_password').value;                    
  75.                 
  76.                 if (username.length == 0 || password.length == 0)
  77.                 {
  78.                         RIL.APP.PROMPT.alert(window, 'Read It Later', RIL.l('mustEnterUserAndPass') );
  79.                         return false;
  80.                 }
  81.                                 
  82.                 
  83.                 RIL.addClass( RIL.xul('login') , RIL.XULnamespace + 'loading' );
  84.                 RIL.APP.SYNC.signup(username, password, this, 'signupCallback');            
  85.         },
  86.  
  87.         signupCallback : function(request)
  88.         {                
  89.                 RIL.removeClass( RIL.xul('login') , RIL.XULnamespace + 'loading' );
  90.                 
  91.                 if (request.success)
  92.                 {
  93.                         this.saveLogin('signup');
  94.                         
  95.                         // Sync and show list
  96.                         try {
  97.                                 
  98.                                 let w = this.getTopWindow();    
  99.                                 
  100.                                 w.RIL.openListAfterLogin();
  101.                                 
  102.                                 window.close();
  103.                                 
  104.                         } catch(e) {
  105.                                 // if we can't connect to the current window, just give up and close the login dialog
  106.                                 window.close();
  107.                         }
  108.  
  109.                 }
  110.                 else
  111.                 {
  112.                         this.handleError(request, 'logging in');
  113.                 }
  114.         },
  115.  
  116.         noAccount : function(request)
  117.         {                
  118.                 let w = this.getTopWindow();    
  119.                 
  120.                 w.RIL.openListAfterLogin();
  121.                 
  122.                 window.close();
  123.         },
  124.         
  125.         saveLogin : function(which)
  126.         {
  127.                 RIL.APP.saveLogin( RIL.xul(which+'_username').value , RIL.xul(which+'_password').value);
  128.         },
  129.         
  130.         handleError : function(request, action)
  131.         {
  132.                 let check = {value: false};
  133.                 var flags = RIL.APP.PROMPT.BUTTON_POS_0 * RIL.APP.PROMPT.BUTTON_TITLE_OK +
  134.                                         RIL.APP.PROMPT.BUTTON_POS_1 * RIL.APP.PROMPT.BUTTON_TITLE_IS_STRING;
  135.  
  136.  
  137.                 let button = RIL.APP.PROMPT.confirmEx(window, "Read It Later",
  138.                                         "There was a problem "+action+":\n\n"+request.error,
  139.                                         flags, 
  140.                                          "", "Get Help", "",
  141.                                          null, check
  142.                 );
  143.                 
  144.                 if (button == 1)
  145.                         window.open('http://readitlaterlist.com/support/');
  146.                         
  147.         },
  148.         
  149.         getTopWindow : function()
  150.         {
  151.                 let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  152.                                 .getService(Components.interfaces.nsIWindowMediator);
  153.                 let w = wm.getMostRecentWindow("navigator:browser");
  154.  
  155.                 return w ? w : window.opener;
  156.         }
  157.         
  158. }
  159. RILlogin = new RILlogin();